import mysql.connector

# 将连接信息存入字典中
conn_params = {
    "host": "127.0.0.1",
    "user": "haojg",
    "password": "haojg",
    "database": "stocks",
}

# 使用 ** 运算符传递字典参数
cnx = mysql.connector.connect(**conn_params)

# 获取游标
cursor = cnx.cursor()

# 定义字典类型的参数
params = {"startDate": "2017-08-01"}
# 执行查询
cursor.execute(
    "SELECT * FROM t_stock_k_minute_data where sd_date > %(startDate)s", params=params
)

# 将查询结果放到列表中
rows = cursor.fetchall()

# 遍历查询结果
for row in rows:
    print(row)

# 关闭游标和连接
cursor.close()
cnx.close()
